import { useModel } from "umi";
import { useReactive } from "ahooks";

const useDeleteLogFile = () => {
    const { remoteData } = useModel("global");
    const { selectedGateway } = useModel("gateway.info");

    const state = useReactive({
        loading: false,
        logContent: [],
    });

    const deleteLogFile = async (filename, callback) => {
        if (!selectedGateway.url) return;
        state.loading = true;
        let res = await remoteData({
            object: "multi-person-gateway",
            p2pNodeUuid: selectedGateway.uuid,
            serviceUrl: selectedGateway.url,
            serviceName: "/logs/deleteLogsFile",
            params: { filename },
        });
        res && callback && callback(res);
        state.loading = false;
    };

    return { ...state, deleteLogFile };
};

export default useDeleteLogFile;
